/**
 * Created by joy on 12/09/2017.
 */
import EthRpcHelper from '../../common/helpers/chain/EthRpcHelper'
import fs from 'fs'
import EthWalletHelper from '../../common/helpers/chain/EthWalletHelper'
import CommonUtil from '../../common/utils/CommonUtil'
import prompt from 'prompt'

export default async () => {
  const schema = {
    properties: {
      privateKey: {
        description: 'Enter privateKey',
        type: 'string',
        required: true,
        default: '0x6b406fa165e1507ffc49f9b53914fb1d6871c310d6488653d40ce5016c0eed1c'
      },
      contractFile: {
        description: 'Enter contract file',
        type: 'string',
        required: true,
        default: 'src/sols/token.sol'
      },
      nonce: {
        description: 'Enter nonce',
        type: 'number',
        required: true,
      },
    }
  }

  const args = await CommonUtil.getArgsFromConsole(prompt, schema)
  const { privateKey, contractFile, nonce } = args
  const ethRpcHelper = new EthRpcHelper(), ethWalletHelper = new EthWalletHelper()
  const input = fs.readFileSync(contractFile)
  const compiled = await ethWalletHelper.compileContract(input.toString())
  const txHex = ethWalletHelper.buildDeployContractTx(ethRpcHelper, compiled, privateKey, nonce)
  logger.info('txHex', txHex)
}
